package com.example.base.demo;

import com.example.base.demo.configuration.TestConfiguration;
import com.example.base.demo.configuration.TestConfiguration001;
import com.example.base.demo.configuration.TestImportAutoConfiguration;
import com.example.base.demo.configuration.TestService;
import com.example.base.demo.pojo.Animal;
import com.example.base.demo.sp.MyListener;
import com.example.base.test.TestScanProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.core.metrics.jfr.FlightRecorderApplicationStartup;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.Properties;


@SpringBootApplication
@ImportAutoConfiguration(TestImportAutoConfiguration.class)
@EnableScheduling
@EnableAsync
// @ComponentScan({"com.example.base.demo","com.example.base.test"})
@ConfigurationPropertiesScan("com.example.base.test")
public class SpringBoot3BaseDemoApplication {

    // 使用slf4j API 创建记日志纪录器
    private static final Logger logger = LoggerFactory.getLogger(SpringBoot3BaseDemoApplication.class);


    @Autowired
    Animal animal;


    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(SpringBoot3BaseDemoApplication.class);
        ConfigurableApplicationContext applicationContext = application.run(args);
        // proxyBeanMethods: true

        String[] namesForType = applicationContext.getBeanNamesForType(TestScanProperties.class);

        System.out.println("===================================");
        // 规范名称应为小写字母数字字符，并且必须以字母开头
        //application.setEnvironmentPrefix("pearl");
        //application.setApplicationStartup(new FlightRecorderApplicationStartup());
        // 设置环境
        //application.setAdditionalProfiles("dev");
        //Object messageSourceUtils = applicationContext.getBean("messageSourceUtils");
        //SpringApplication springApplication = new SpringApplication(SpringBoot3BaseDemoApplication.class);
        //springApplication.addListeners(new MyListener());
        //springApplication.run(args);
        //System.exit(SpringApplication.exit(SpringApplication.run(SpringBoot3BaseDemoApplication.class, args)));
        //ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBoot3BaseDemoApplication.class, args);
        // ConfigurableApplicationContext applicationContext = MySpringApplication.run(SpringBoot3BaseDemoApplication.class, args);
/*
        application.setLazyInitialization(false);
        application.setLogStartupInfo(false);
        application.setAllowBeanDefinitionOverriding(false);
        application.run(args);*/

/*        new SpringApplicationBuilder()
                .sources(SpringBoot3BaseDemoApplication.class)
                .allowCircularReferences(false)
                .run(args);*/





/*        // 1. 直接打印日志
        logger.info("程序启动完成了...");
        // 2. 使用 {} 占位符
        logger.info("启动端口：{}", applicationContext.getEnvironment().getProperty("server.port"));
        // 3. 根据当前日志级别打印日志
        if (logger.isDebugEnabled()) {
            // 如果开启了Debug 才打印Debug日志
            logger.debug("如果开启了Debug,才打印Debug日志");
        }*/
    }
}
